package com.tt.mymu.service.Impl;

import com.tt.mymu.entity.Carousel;
import com.tt.mymu.mapper.CarouselMapper;
import com.tt.mymu.service.CarouselService;
import com.tt.mymu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CarouselServiceImpl implements CarouselService {
    @Autowired
    private CarouselMapper carouselMapper;
    @Value("${tool.updateFile.img}")
    private String toolUpdateImg;
    @Value("${tool.updateFile.video}")
    private String toolUpdateVideo;

    @Value("${nginx.url}")
    private String nginxUrl;

    @Override
    public Result getListCarousel() {

        List<Carousel> carousels = carouselMapper.selectList(null);
        return Result.success(carousels);
    }

    @Override
    public Result deleteCarouselById(int id) {
        int i = carouselMapper.deleteById(id);
        return Result.success(i);
    }

    @Override
    public Result addCarousel(Carousel carousel) {
        carousel.setSrc("http://" + carousel.getSrc());
        carousel.setCreateTime(new Date());
        int insert = carouselMapper.insert(carousel);
        return Result.success(insert);
    }
}
